package gui.panels;

import gui.tools.ActionHandler;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import mysql.MoviesQueries;
import mysql.SeriesQueries;
import objects.Movie;
import objects.Series;

public class SeriesPanel extends JPanel {

	public Series scurrentEntry;
	public SeriesQueries sseriesQueries;
	public List<Series> sResults;
	public int snumberOfEntries = 0;
	public int sCurrentEntryIndex = 0;

	public JTextField seidText;
	private JLabel seidLabel;
	public JTextField titleText;
	private JLabel titleLabel;
	public JTextField seasonText;
	private JLabel seasonLabel;
	public JTextField episodeText;
	private JLabel episodeLabel;
	public JTextField lidText;
	private JLabel lidLabel;
	public JTextField outText;
	private JLabel outLabel;

	public JButton add;
	
	
	public JButton next;
	public JButton previous;
	public JPanel navigatePanel;
	public JTextField index;
	private JPanel displayPanel;

	public SeriesPanel(ActionHandler ac) {
		getData();
		seidLabel = new JLabel("Series ID:");
		seidText = new JTextField(2);
		titleLabel = new JLabel("Title:");
		titleText = new JTextField(10);
		seasonLabel = new JLabel("Season:");
		seasonText = new JTextField(10);
		episodeLabel = new JLabel("Episode:");
		episodeText = new JTextField(10);
		lidLabel = new JLabel("Location ID:");
		lidText = new JTextField(2);
		outLabel = new JLabel("Is out:");
		outText = new JTextField(5);
		
		add = new JButton("Add new series");

		if (sResults.get(sCurrentEntryIndex).isOut() == 0) {
			outText.setText("False");
		} else
			outText.setText("True");

		next = new JButton("Next");
		previous = new JButton("Previous");
		navigatePanel = new JPanel();
		index = new JTextField(2);
		displayPanel = new JPanel();

		seidText.setEditable(false);
		titleText.setEditable(false);
		seasonText.setEditable(false);
		episodeText.setEditable(false);
		lidText.setEditable(false);
		outText.setEditable(false);

		setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));

		next.addActionListener(ac);
		previous.addActionListener(ac);
		navigatePanel.setLayout(new BoxLayout(navigatePanel, BoxLayout.X_AXIS));
		navigatePanel.add(previous);
		navigatePanel.add(Box.createHorizontalStrut(10));
		navigatePanel.add(index);
		navigatePanel.add(Box.createHorizontalStrut(10));
		navigatePanel.add(next);
		add(navigatePanel);

		displayPanel.setLayout(new GridLayout(6, 2, 4, 4));
		displayPanel.add(seidLabel);
		seidText.setEditable(false);
		displayPanel.add(seidText);
		displayPanel.add(titleLabel);
		displayPanel.add(titleText);
		displayPanel.add(seasonLabel);
		displayPanel.add(seasonText);
		displayPanel.add(episodeLabel);
		displayPanel.add(episodeText);
		displayPanel.add(lidLabel);
		displayPanel.add(lidText);
		displayPanel.add(outLabel);
		displayPanel.add(outText);

		add.addActionListener(ac);
		add(displayPanel);
		add(add, BorderLayout.SOUTH);

	}

	private void getData() {
		sseriesQueries = new SeriesQueries();
		sResults = sseriesQueries.getAllSeries();
	}
}